/**
 * 历史记录，岗位发布信息
 */
import React from 'react';
import { get as getPath } from 'object-path';
import { Descriptions } from '../../components';
import { arrJobType } from '../../../containers/channel/bossStaticDict';
import useChannelDict from '../../../containers/channel/useChannelDict';

const PublishDetail = ({ data = {} }) => {
    const { channelCode, channelRecruitInfo } = data;

    const {
        workNature = [],
        recruitType = [],
        workExperience = [],
        educationDegree = [],
        feedbackPeriod = [],
        positionIndustry = []
    } = useChannelDict(channelCode, [
        'workNature',
        'recruitType',
        'workExperience',
        'educationDegree',
        'feedbackPeriod',
        'positionIndustry'
    ]);

    const getLaGouPoint = () => {
        const { extraInfor } = channelRecruitInfo;
        if (!extraInfor) {
            return '--';
        }
        let arr = [];
        try {
            arr = JSON.parse(extraInfor)?.[0]?.labels;
        } catch (error) {
            console.log(error);
        }
        return arr.map(item => item.name).join('、');
    };

    const getValue = (arr, value) =>
        arr.find(item => item.selectValue === getPath(channelRecruitInfo, value))?.selectName || '--';

    const getCompanyIndustry = () => {
        const arr = getPath(channelRecruitInfo, 'industries', [])?.map(
            o => positionIndustry?.find(item => item.selectValue === o)?.selectName
        );
        return arr?.filter(item => item)?.length > 0 ? arr.join('、') : '--';
    };
    // channelRecruitInfo的内容都是第三方要求的字段，字段都是动态，无法单独处理，请前端处理
    const getValueText = (obj, value, defaultValue) => obj[value] || defaultValue;

    const options = {
        xmrc: [
            { label: '职位名称', value: getPath(channelRecruitInfo, 'JobName', '--'), required: true },
            { label: '职位类别', value: getPath(channelRecruitInfo, 'JobTypesName', '--'), required: true },
            { label: '工作地址', value: getPath(channelRecruitInfo, 'channelWorkCityName', '--'), required: true },
            {
                label: '薪资范围',
                value: `${getPath(channelRecruitInfo, 'SalaryMin', '--')}-${getPath(
                    channelRecruitInfo,
                    'SalaryMax',
                    '--'
                )}`,
                // )} ${channelRecruitInfo?.SalaryMin ? salaryCurrencyCode : ''}`,
                required: true
            },
            {
                label: '最低学历',
                value: getPath(channelRecruitInfo, 'NeedEduBackgroundName', '--'),
                required: true
            },
            {
                label: '工作年限',
                value: getPath(channelRecruitInfo, 'NeedWorkLengthName', '--'),
                required: true
            },
            {
                label: '职位描述',
                value: getPath(channelRecruitInfo, 'JobDetailCn', '--'),
                required: true
            },
            { label: '招聘人数', value: getPath(channelRecruitInfo, 'NeedAmount', '0'), required: true }
        ],
        bosszp: [
            { label: '职位名称', value: getPath(channelRecruitInfo, 'positionName', '--'), required: true },
            { label: '职位类别', value: getPath(channelRecruitInfo, 'positionCategory', '--'), required: true },
            {
                label: '职位关键词',
                value: getPath(channelRecruitInfo, 'skillList', [])
                    ? getPath(channelRecruitInfo, 'skillList', []).join(';')
                    : '--',
                required: true
            },
            {
                label: '招聘类型',
                value: arrJobType.find(item => item.Id === getPath(channelRecruitInfo, 'jobType'))?.Name,
                required: true
            },
            { label: '工作地址', value: getPath(channelRecruitInfo, 'channelWorkCityName', '--'), required: true },
            {
                label: '薪资范围',
                value: `${getPath(channelRecruitInfo, 'lowSalary', '--')}k-${getPath(
                    channelRecruitInfo,
                    'highSalary',
                    '--'
                )}k ${getPath(channelRecruitInfo, 'salaryMonth', '--')}薪`,
                // )}k ${getPath(channelRecruitInfo, 'salaryMonth', '--')}薪 ${salaryCurrencyCode}`,
                required: true
            },
            {
                label: '最低学历',
                value: educationDegree?.find(item => item.selectValue === getPath(channelRecruitInfo, 'degree'))
                    ?.selectName,
                required: true
            },
            {
                label: '工作年限',
                value: workExperience?.find(item => item.selectValue === getPath(channelRecruitInfo, 'experience'))
                    ?.selectName,
                required: true
            },
            {
                label: '职位描述',
                value: getPath(channelRecruitInfo, 'description', '--'),
                required: true
            }
        ],
        liepin: [
            { label: '职位名称', value: getPath(channelRecruitInfo, 'ejobTitle', '--'), required: true },
            { label: '职位类别', value: getPath(channelRecruitInfo, 'positionCategoryNames', '--'), required: true },
            {
                label: '职位亮点',
                value: getPath(channelRecruitInfo, 'detailTags', '--'),
                required: true
            },
            { label: '工作地址', value: getPath(channelRecruitInfo, 'channelWorkCityName', '--'), required: true },
            {
                label: '薪资范围',
                value: `${getPath(channelRecruitInfo, 'ejobMonthlysalaryLow', '--')}k-${getPath(
                    channelRecruitInfo,
                    'ejobMonthlysalaryHigh',
                    '--'
                )}k ${getPath(channelRecruitInfo, 'ejobSalaryMonth', '--')}薪`,
                // )}k ${getPath(channelRecruitInfo, 'ejobSalaryMonth', '--')}薪 ${salaryCurrencyCode}`,
                required: true
            },
            {
                label: '最低学历',
                value: educationDegree?.find(item => item.selectValue === getPath(channelRecruitInfo, 'detailEdulevel'))
                    ?.selectName,
                required: true
            },
            {
                label: '工作年限',
                value: workExperience?.find(
                    item => item.selectValue === getPath(channelRecruitInfo, 'detailWorkyearArea')
                )?.selectName,
                required: true
            },
            {
                label: '职位描述',
                value: getPath(channelRecruitInfo, 'detailDutyQualify', '--'),
                required: true
            },
            {
                label: '反馈时长',
                value: getValue(feedbackPeriod, 'feedbackPeriod'),
                required: true
            }
        ],
        lagou: [
            {
                label: '招聘类型',
                value: `${getValue(recruitType, 'isSchoolJob')}/${getValue(workNature, 'jobNature')}`,
                required: true
            },
            { label: '职位名称', value: getPath(channelRecruitInfo, 'positionName', '--'), required: true },
            {
                label: '职位类别',
                value: `${getPath(channelRecruitInfo, 'firstType', '--')}/${getPath(
                    channelRecruitInfo,
                    'positionType',
                    '--'
                )}/${getPath(channelRecruitInfo, 'positionThirdType', '--')}`,
                required: true
            },
            {
                label: '经验和学历',
                value: `${getPath(channelRecruitInfo, 'workYear', '--')}/${getPath(
                    channelRecruitInfo,
                    'education',
                    '--'
                )}`,
                required: true
            },
            { label: '工作地址', value: getPath(channelRecruitInfo, 'channelWorkCityName', '--'), required: true },
            {
                label: '薪资范围',
                value: `${getPath(channelRecruitInfo, 'salaryMin', '--')}k-${getPath(
                    channelRecruitInfo,
                    'salaryMax',
                    '--'
                )}k ${getPath(channelRecruitInfo, 'salaryMonth', '--')}薪`,
                // )}k ${getPath(channelRecruitInfo, 'salaryMonth', '--')}薪 ${salaryCurrencyCode}`,
                required: true
            },
            {
                label: '职位关键词',
                value: getLaGouPoint(),
                required: true
            },
            {
                label: '职位亮点',
                value: getPath(channelRecruitInfo, 'positionBrightPoint', '--'),
                required: true
            },
            {
                label: '职位描述',
                value: getPath(channelRecruitInfo, 'positionDesc', '--'),
                required: true
            }
        ],
        mmzp: [
            { label: '职位名称', value: getPath(channelRecruitInfo, 'position', '--'), required: true },
            {
                label: '行业',
                value: `${getPath(channelRecruitInfo, 'profession_text', '--')}`,
                required: true
            },
            {
                label: '行业方向',
                value: `${getPath(channelRecruitInfo, 'major_new_text', '--')}`,
                required: true
            },
            {
                label: '人才方向',
                value: `${getValueText(channelRecruitInfo, 'major_new_lv2_text', '--')}`
            },
            {
                label: '经验和学历',
                value: `${getValue(workExperience, 'work_time')}/${getValue(educationDegree, 'degree')}`,
                required: true
            },
            { label: '工作地址', value: getValueText(channelRecruitInfo, 'channelWorkCityName', '--'), required: true },
            {
                label: '薪资范围',
                value: `${getPath(channelRecruitInfo, 'salary_min', '--')}-${getPath(
                    channelRecruitInfo,
                    'salary_max',
                    '--'
                )} ${getPath(channelRecruitInfo, 'salary_share', '--')}薪`,
                // )} ${getPath(channelRecruitInfo, 'salary_share', '--')}薪 ${salaryCurrencyCode}`,
                required: true
            },
            {
                label: '职位亮点',
                value: getValueText(channelRecruitInfo, 'custom_text', '--')
            },
            {
                label: '职位描述',
                value: getPath(channelRecruitInfo, 'description', '--'),
                required: true
            }
        ],
        linkedin: [
            {
                label: 'Job title',
                value: getPath(channelRecruitInfo, 'title', '--'),
                required: true
            },
            {
                label: 'Job function',
                value:
                    getPath(channelRecruitInfo, 'jobFunctions', [])
                        ?.map(item => item.displayName)
                        ?.join('、') || '--',
                required: true
            },
            {
                label: 'Company industry',
                value: getCompanyIndustry(),
                required: true
            },
            {
                label: 'Employment type',
                value: getPath(channelRecruitInfo, 'employmentStatus.displayName', '--'),
                required: true
            },
            {
                label: 'Seniority level',
                value: getPath(channelRecruitInfo, 'experienceLevel.displayName', '--'),
                required: true
            },
            {
                label: 'Receive notification email',
                value: getPath(channelRecruitInfo, 'contactEmail', '--'),
                required: true
            },
            {
                label: 'Target your job post',
                value: getPath(channelRecruitInfo, 'skills.includedSkillsName', [])?.join('、') || '--',
                required: true
            },
            {
                label: 'Add to a project',
                value: getPath(channelRecruitInfo, 'project_name', '--'),
                required: true
            },
            {
                label: 'Job description',
                value: getPath(channelRecruitInfo, 'description', '--'),
                required: true
            }
        ]
    };

    return (
        <Descriptions descriptions={options[channelCode]} labelWidth={channelCode === 'linkedin' ? 200 : undefined} />
    );
};

export default PublishDetail;
